<template>
	<view class="px-2">
		<view v-for="(item,index) in topics" :key="index">
			
			<view  class="shadow rounded text-light-black font font-weight-bold my-3">
				<u-skeleton :loading="loading" :animate="true" rows="1">
					<view class=" p-1 bg-light-muted rounded-top flex">
						<view class="d-inline-block">
							<text style="word-wrap: break-word;">{{index+1}}.{{item.content}}</text>
						</view>
						
					</view>
					
				</u-skeleton>
				 
						<view class="flex justify-center">
							
								<view class="flex-1 " v-if="item.img && item.img!=''">
									<u-skeleton :loading="loading" :animate="true" rows="1" >
										<view class="flex justify-center ">
											<view class="p-2 ">
													<image class="rounded-lg" :src="item.img" style="width: 250rpx;height: 200rpx;" mode=""></image>
											 </view>
										</view> 
										
										 </u-skeleton>
									</view>
							
							 
						
							<u-skeleton :loading="loading" :animate="true" rows="1">
								<view class="flex-2 flex  justify-center  flex-column   justify-center">
															 				
								 <block   v-for="(option,index) in item.options"  :key="index">
									
									<!-- {{index}}
									 {{item.answer.findIndex(x=>x===index)}} -->
									<view class=" px-2 mt-2" :class="item.answer.findIndex(x=>x==index)==-1?'error':'correct'"    >
										
										<view  class="d-inline-block  p-1 text-center  font-sm" style="line-height: 30rpx; width: 30rpx;height: 30rpx;">		
											<text >{{String.fromCharCode(index+65)}}</text>
										</view>
										<view class="d-inline-block px-1" > 
											<text class="font-sm">{{option}}</text>
										</view>
									</view> 
										
								 </block>
							 </view> 
							</u-skeleton>	
							
							 
							
						</view> 
							<u-skeleton :loading="loading" :animate="true" rows="1">
						<view class="flex justify-center align-center  rounded-bottom font border-top" style="color: #FF2C02;">
							错{{countobj[item._id]}}次
						</view>
						</u-skeleton>
					</view>
					
		</view>
		
		
	</view>
</template>
 
<script>
	export default {
		data() { 
			return {
				countobj:{},
				loading:true,
				topics:[
					{
						content:'21321312',
						type:'选择题',
						img:'https://s3.bmp.ovh/imgs/2022/04/14/189131458c3548d7.gif',
						options:['1','2','3'],
						answer:[0]
					},
					{
						content:'21321312',
						type:'选择题',
						img:'https://s3.bmp.ovh/imgs/2022/04/14/189131458c3548d7.gif',
						options:['1','2','3'],
						answer:[0,1,2]
						
					}
				]
			}
		},
		async onLoad() {
			uni.showNavigationBarLoading()
			let res= await this.$c.getUser(uni.getStorageSync('openid'))
			let error_ti=res.result.data.error_ti
		
			for(let i=0;i<error_ti.length;i++)
			{
				if(error_ti[i] in this.countobj)
				{
					this.countobj[error_ti[i]]+=1
				}
				else
				{
					this.countobj[error_ti[i]]=1
				}
			}
			error_ti=Array.from(new Set(error_ti))
			error_ti.sort((a,b)=>this.countobj[b]-this.countobj[a])
			console.log(this.countobj)
			
		
			let promiselist=[]
			for(let i=0;i<error_ti.length;i++)
			{
				promiselist.push(this.$c.getti(error_ti[i]))
			} 
			console.log("开始拉取")
			Promise.all(promiselist).then(e=>{
				console.log(e)
				this.topics=e.map(x=>{return x.result.data})
				this.topics=this.topics.map(x=>{
					x.answer.sort((a,b)=>a-b)
					return x
				}) 
				uni.hideNavigationBarLoading()
				this.loading=false
			}).catch(e=>{
				console.log(e)
			})
			
			// console.log(this.topics) 
			
		},
		methods: {
			
		}
	}
</script>

<style scoped>
.correct
{
	color: #00CF97;
	background-color: #efefef;
}
.error
{
	color: #ff5500; 
}
</style>
